public class QuadraticEquation {
    private double a;
    private double b;
    private double c;

    // 构造函数
    public QuadraticEquation(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    // 方法计算方程的根
    public void solve() {
        // 计算判别式
        double discriminant = b * b - 4 * a * c;

        if (discriminant > 0) {
            // 两个不同的实根
            double root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
            double root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
            System.out.println("两个不同的实根: " + root1 + " 和 " + root2);
        } else if (discriminant == 0) {
            // 一个实根
            double root = -b / (2 * a);
            System.out.println("一个实根: " + root);
        } else {
            // 复根
            double realPart = -b / (2 * a);
            double imaginaryPart = Math.sqrt(-discriminant) / (2 * a);
            System.out.println("两个复根: " + realPart + " + " + imaginaryPart + "i 和 " + realPart + " - " + imaginaryPart + "i");
        }
    }
}